package classes.view
{
	import classes.OX_Application;
	import classes.model.VOData;
	import classes.view.component.GameRoom;
	import classes.view.component.InfoBar;
	import classes.view.component.ListRoom;
	import classes.view.component.LoadingBar;
	import classes.view.component.Logo;
	import classes.view.component.Main;
	import classes.view.component.Notice;
	import classes.view.component.Popup;
	import classes.view.component.SingleRoom;
	import classes.view.component.WaitingRoom;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class Mediator_Main extends Mediator implements IMediator
	{
		public static const NAME:String = "Mediator_Main";
		public function Mediator_Main(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			setMainRegisterMediator();
		}
		
		private function setMainRegisterMediator():void
		{
			//main안의 component 등록.
			var logo:Logo		 		= main.getChildByName('logo_mc')					as Logo;
			var infoBar:InfoBar 		= main.getChildByName('infobar_mc')					as InfoBar;
			var notice:Notice			= main.getChildByName('notice_mc')					as Notice;
			var listroom:ListRoom		= main.getChildByName('listroom_mc')				as ListRoom;
			var waitingroom:WaitingRoom	= main.getChildByName('waitingroom_mc')				as WaitingRoom;
			var gameroom:GameRoom		= main.getChildByName('gameroom_mc')				as GameRoom;
			var singleroom:SingleRoom	= main.getChildByName('singleroom_mc')				as SingleRoom;
			var popup:Popup				= main.getChildByName('popup_mc')					as Popup;
			var loading:LoadingBar		= main.getChildByName('loadingbar_mc')				as LoadingBar;	
			
			//main안의 mediator 등록.
			facade.registerMediator(new Mediator_Logo(Mediator_Logo.NAME,					logo));
			facade.registerMediator(new Mediator_Infobar(Mediator_Infobar.NAME,				infoBar));
			facade.registerMediator(new Mediator_Notice(Mediator_Notice.NAME,				notice));
			facade.registerMediator(new Mediator_ListRoom(Mediator_ListRoom.NAME,			listroom));
			facade.registerMediator(new Mediator_Waitingroom(Mediator_Waitingroom.NAME, 	waitingroom));
			facade.registerMediator(new Mediator_GameRoom(Mediator_GameRoom.NAME,			gameroom));
			facade.registerMediator(new Mediator_SingleRoom(Mediator_SingleRoom.NAME,		singleroom));
			facade.registerMediator(new Mediator_Popup(Mediator_Popup.NAME,					popup));
			facade.registerMediator(new Mediator_Load(Mediator_Load.NAME,					loading));
			
			//첫 실행.
			selectFirstPage 			= VOData.getDataInstance().mod;
			
			
		}
		
		private function set selectFirstPage($mode:int):void
		{
			switch($mode){
				case 1:
					//trace('기존 사용');
					sendNotification(OX_Application.APPLICATION_EXECUTE);
				break;
				case 2:
					//trace('사용자가 처음으로 실행했을 경우');
					sendNotification(OX_Application.THE_FIRST_EXECUTE);
				break;
				case 3:
					//trace('오답노트를 통해서 실행했을 경우');
					sendNotification(OX_Application.INCORRECTQUESTION_EXECUTE);
				break;
				default :
					sendNotification(OX_Application.APPLICATION_EXECUTE);
				break;
			}
		}
		
		override public function listNotificationInterests():Array
		{
			return [];
		}
		override public function handleNotification(notification:INotification):void
		{
			/*switch(notification.getName()){
				case OX_Application.XXX :
					
				break;
			}*/
		}
		protected function get main():Main
		{
			return viewComponent as Main;
		}
		
	}
}